package com.wise.site.protocol.result;

import org.json.JSONObject;

import com.wise.site.protocol.base.SoapResult;
import com.wise.site.utils.Constanct;

public class LoginResult extends SoapResult {
	/**
	 * 用户id
	 */
	public int id;
	/**
	 * 商铺id
	 */
	public int shopId;
	//商铺用户昵称
	public String nickname;
	//商铺用户头像链接
	public String portraitImageUrl;
	//商铺名称
	public String userName;
	//商铺logo链接
	public String logoImageUrl;
	//商铺等级
	public int level;
	//商铺等级名称
	public String levelNmae;
	//商铺描述
	public String description;
	//商铺地址
	public String address;
	//商铺联系电话
	public String phone;
	//商铺邮件邮址     --->email
	public String email;
	//商铺官网         --->officialWebsite
	public String officialWebsite;
	//商铺是否被推荐   --->recommended      		
	public boolean recommended;
	//商铺所属类别     --->category         	
	public String category;
	
	public String msg;
	public int flag;

	@Override
	public void parseData(String response) throws Exception {
		JSONObject json = new JSONObject(response);
		flag = json.getInt("flag");
		try{
			if(flag == 1){
				json = new JSONObject(json.getString("msg"));
				id = json.getInt("userId");
				
				nickname = json.getString("nickname");
				
				if(!json.isNull("portraitImageUrl")){
					portraitImageUrl = Constanct.IMAGE_PREFIX + json.getString("portraitImageUrl");
				}
				
				if(!json.isNull("username")){
					userName = json.getString("username");
				}
				
				if(!json.isNull("logoImageUrl")){
					logoImageUrl = Constanct.IMAGE_PREFIX + json.getString("logoImageUrl");
				}
				
				level = json.getInt("levelid");
				levelNmae = json.getString("levelname");
				
				if(!json.isNull("description")){
					description = json.getString("description");
				}
				
				if(!json.isNull("address")){
					address = json.getString("address");
				}
				
				if(!json.isNull("phone")){
					phone = json.getString("phone");
				}
				
				if(!json.isNull("email")){
					email = json.getString("email");
				}
				
				if(!json.isNull("officialWebsite")){
					officialWebsite = json.getString("officialWebsite");
				}
				
				if(!json.isNull("recommended")){
					recommended = json.getInt("recommended") == 1;
				}
				
				if(!json.isNull("category")){
					category = json.getString("category");
				}
				
				if(!json.isNull("shopId")){
					shopId = json.getInt("shopId");
				}
			} else {
				msg = json.getString("msg");
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
	}

}
